<?
	App::import('Model', 'Usuario');

class UserSessionComponent extends Object
	{

		//var $model = null;
		var $controller = null;
		var $User = null;
		var $components = array('Session');


		function initialize(&$controller) 
		{
			//$this->model  = new model(false, false);
			$this->controller =& $controller;
			$this->Usuario = new Usuario();
		}

		function checkSession($redirect=true)
		{
			$error = false;

			if (!$this->Session->check('User'))
			{
				$this->Session->setFlash('Su sesion ha expirado, por favor ingrese nuevamente', 'default', array('class' => 'blue_screen_error'), 'blue_screen_error');
				$error = true;
			}


			if ($error)
			{
				$this->Session->write('solicited_page', str_replace('url=', '/', $_SERVER ['QUERY_STRING'] ));
				if ($redirect)
				{
					$this->controller->redirect(array('controller'=>'dashboard', 'action'=>'index')); exit();
				}
				else
				{
					return false;
				}
			}
			else
			{
				return true;
			}
		}

		function userLogued(){
			return $this->Session->check('User');
		}

		function get()
		{
			$this->checkSession();
			return $this->Session->read('User');
		}

		function start($data)
		{
			return $this->Session->write('User', $data);
		}

		function stop()
		{
			$this->Session->delete('User');
		}
}
?>
